package com.vrv.common.utils;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.vrv.common.Constants;
/**
 * 获取json对象中内容
 * @author zxb
 *
 */
public class JsonUtil {
    private static final String TAG = JsonUtil.class.getSimpleName();
    private static final boolean DEBUG = true && Constants.DEBUG;
    /**
     * 获取JSONObject类型String
     * @param jsonObject
     * @param key
     * @return
     */
    public static String getJsonString(JSONObject jsonObject, String key){
        if(DEBUG) Log.v(TAG, "checkJsonString()");
        
        String ret = "";
        try {
            if (null == jsonObject) return ret;
            if (jsonObject.isNull(key)) return ret;
            ret = jsonObject.getString(key);
            
            /**update by zxb 20130731 电话号码为空特殊处理*/
            if ("tel".equals(key) && "B".equals(ret)) {
                ret = "";
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return ret;
    }
    
    /**
     * 获取JSONObject类型long
     * @param jsonObject
     * @param key
     * @return
     */
    public static long getJsonLong(JSONObject jsonObject, String key){
        if(DEBUG) Log.v(TAG, "checkJsonLong()");
        
        long ret = 0;
        try {
            if (null == jsonObject) return ret;
            if (jsonObject.isNull(key)) return ret;
            ret = jsonObject.getLong(key);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return ret;
    }
}
